jQuery(document).ready(function(){
	
		//hide the colorbox title
		jQuery("#cboxTitle").hide();
		
		//parse the query string so we can use the query string items to determine the action
		function getUrlVars()
		{
		    var vars = [], hash;
		    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		    for(var i = 0; i < hashes.length; i++)
		    {
		        hash = hashes[i].split('=');
		        vars.push(hash[0]);
		        vars[hash[0]] = hash[1];
		    }
		    return vars;
		}
		
		var action = getUrlVars()["action"];
		var type = getUrlVars()["type"];
		var category = getUrlVars()["cat"];
		
		//only show the text area if it is a news item
		if (type == "news"){
			jQuery("#postdivrich").show("slow");
		}
		
		//check the category check box of the current category
		jQuery("ul#categorychecklist li #in-category-" + category).attr('checked','checked');
		
	
			
		//disable #publish button until the onblur shows that the required fields are populated.
		//if the action is add disable the publish button
		if (action == "add") {
			jQuery('#publish').attr('disabled', 'disabled');
			
			jQuery("#post-body-content #title").keyup(function(){
				//check if the title is blank or not
				
				if (jQuery("#post-body-content #title").val() == "") {
					jQuery('#publish').attr('disabled', 'disabled');
				}
				else {
					jQuery('#publish').attr('disabled', '');
				}
			});
		 }
		
		if (action == "edit") {
			jQuery('#publish').attr('disabled', '');
			
			jQuery("#post-body-content #title").keyup(function(){
				//check if the title is blank or not
				if (jQuery("#post-body-content #title").val() == "") {
					jQuery('#publish').attr('disabled', 'disabled');
				}
				else {
					jQuery('#publish').attr('disabled', '');
				}
			});
		 }
		
		
		/*
		//check if any checkboxes
		jQuery('#categorychecklist input').each(function() {
			if (jQuery('#categorychecklist input[type="checkbox"]:checked').val() != null){
				jQuery('#publish').attr('disabled', '');
			}
			else {
				jQuery('#publish').attr('disabled', 'disabled');
			} 
		});
		*/
				
		/*
		jQuery("#publish").click(function(){
			
			//do the extra checks
			jQuery("p.error_msg_txt").remove();
			
			if (jQuery("#post-body-content #title").val() == ""){
				jQuery("#flutter-publish-error-message").show();
				jQuery("#post-body-content #title").parent().prepend('<p class="error_msg_txt">ERROR: Please enter a title</p>');
				jQuery("#post-body-content #title").css("background-color", "#FFEBE8");
				var error = true;
			}
			if (jQuery('#categorychecklist input[type="checkbox"]:checked').val() == null) {
				alert("Please select at least 1 category");
				var error = true;
			}
			
			if (error == true) {
				jQuery("#ajax-loading").css("display", "none");
				return false;
			}
			
			
		});
		*/
		
		
});

